package itbour.onetouchshow.activity.myorder;

import com.google.gson.Gson;
import com.lsjr.callback.EncryBeanCallBack;
import com.lsjr.utils.HttpUtils;

import java.util.HashMap;

import itbour.onetouchshow.App;
import itbour.onetouchshow.base.mvp.BasePresenterImpl;
import itbour.onetouchshow.bean.MyCollectBean;
import itbour.onetouchshow.bean.NoDataResult;
import itbour.onetouchshow.constants.AppConfig;
import itbour.onetouchshow.constants.AppConst;
import itbour.onetouchshow.utils.L_;
import itbour.onetouchshow.utils.T_;

/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */

public class MyCollectPresenter extends BasePresenterImpl<MyCollectContract.View> implements MyCollectContract.Presenter {
    public void loadMyCollectList(MyCollectActivity activity) {
        // /yjx/v1/order/getPreWatermarkOrderInfo_v1_0
//        List<Integer> states=new ArrayList<>();
//        states.add(OrderPlatform.YJX_ORDER_TYPE_WATERMARK);
//        states.add(OrderPlatform.YJX_ORDER_TYPE_SECKILL);
//        states.add(OrderPlatform.YJX_ORDER_TYPE_INVOICE);
        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
        stringObjectHashMap.put("device", AppConst.ANDROID_DEVICE);
        stringObjectHashMap.put("userId", App.getUserId());
        //pageNum	是
        stringObjectHashMap.put("pageNum", activity.mPageIndex);
        //页码 pageSize
        stringObjectHashMap.put("pageSize", AppConst.PAGE_SIZE);
        //   页容量
        stringObjectHashMap.put("withTotalPage", 1);
        HttpUtils.getInstance().executeGet(AppConfig.GETUSERCOLLECTLIST_V1_0, stringObjectHashMap, new EncryBeanCallBack() {
            @Override
            protected void onXError(String exception) {
                L_.e(exception);
                T_.showCustomToast(exception);
                mvpView.loadFaild(exception);
            }

            @Override
            protected void onSuccess(String response) {
                NoDataResult noDataResult = new Gson().fromJson(response, NoDataResult.class);
                if (noDataResult.getList() == null || noDataResult.getList().size() == 0) {
                    mvpView.loadFaild("没有数据");
                } else {
                    mvpView.loadSucceed(response);
                }
                L_.e(response);
            }
        });
    }

    public void loadMyCollectListV1_3(MyCollectActivity activity) {
        // /yjx/v1/order/getPreWatermarkOrderInfo_v1_0
//        List<Integer> states=new ArrayList<>();
//        states.add(OrderPlatform.YJX_ORDER_TYPE_WATERMARK);
//        states.add(OrderPlatform.YJX_ORDER_TYPE_SECKILL);
//        states.add(OrderPlatform.YJX_ORDER_TYPE_INVOICE);
        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
        stringObjectHashMap.put("device", AppConst.ANDROID_DEVICE);
        stringObjectHashMap.put("userId", App.getUserId());
        stringObjectHashMap.put("opType", "2");
        //pageNum	是
        stringObjectHashMap.put("pageNum", activity.mPageIndex);
        //页码 pageSize
        stringObjectHashMap.put("pageSize", AppConst.PAGE_SIZE);
        //   页容量
        stringObjectHashMap.put("withTotalPage", 1);
        HttpUtils.getInstance().executeGet(AppConfig.GETUSERCOLLECTLIST_V1_3, stringObjectHashMap, new EncryBeanCallBack() {
            @Override
            protected void onXError(String exception) {
                L_.e(exception);
                T_.showCustomToast(exception);
                mvpView.loadFaild(exception);
            }

            @Override
            protected void onSuccess(String response) {
                NoDataResult noDataResult = new Gson().fromJson(response, NoDataResult.class);
                if (noDataResult.getList() == null || noDataResult.getList().size() == 0) {
                    mvpView.loadFaild("没有数据");
                } else {
                    mvpView.loadSucceed(response);
                }
                L_.e(response);
            }
        });
    }


    public void cancalCollect(MyCollectBean.ListBean listBean) {
        HashMap<String, Object> stringStringHashMap = new HashMap<>();
        stringStringHashMap.put("device", 610);
        stringStringHashMap.put("tmplId", listBean.getId());
        stringStringHashMap.put("userId", App.getUserId());
        stringStringHashMap.put("collect", 0);
        HttpUtils.getInstance().executeGet(AppConfig.SET_CANCEL_MODEL_COLLECT_V10, stringStringHashMap, new EncryBeanCallBack() {
            @Override
            protected void onXError(String exception) {
                if (mvpView != null) {
                    T_.showCustomToast("取消失败");
                }
            }

            @Override
            protected void onSuccess(String response) {
                L_.i("SET_CANCEL_MODEL_COLLECT_V10===" + response + "id===" + listBean.getId());
                if (mvpView != null) {
                    //T_.showToastReal("取消收藏");
                    mvpView.cancleCollectSuccess(listBean);
                }
            }
        });
    }

}
